#include <iostream>
#include <memory>

using namespace std;

class A;
void fun2(shared_ptr<A> a);

class A : public enable_shared_from_this<A> {
public:
    A(int a) : a_(a) {};
    A() = default;

    ~A() {
        cout << "A::~A()" << endl;
    }
    void fun() {
        cout << "A::fun" << endl;
        fun2(shared_from_this());
    }
    int a_ = 1;
};

void fun2(shared_ptr<A> a) {
    cout << "fun" << endl;
    // cout << "a " << a->a_ << endl;
    // cout << a.use_count() << endl;
}

int main() {
    A a{10};
    a.fun();
    return 0;
}